zeek67(index.js and index.html ,about.html , services.html , contact.html )


index.js


//In this nodejs we have made a page with fully working navbar by nodejs using custom
 backend.

//Steps to create custom backend
//1- Set (http and fs) setup by require.
//2-Use nodejs site about and copy paste code.
//3-Create html pages and link them to js file by fs.readFileSync
//4-Write url=req url; to create url .
//5- Use if and else statement to create conditions for url to work for different
  pages.
//6-Run the server.


//1- Set (http and fs) setup by require.
const http = require('http');
const fsrequire('fs');

const hostname = '127.0.0.1';
const port = 3000;

//Making html pages and linking them
const homefs.readFileSync('./index.html');
const aboutfs.readFileSync('./about.html');
const servicesfs.readFileSync('./services.html');
const contactfs.readFileSync('./contact.html');

const server = http.createServer((reqres=> {
//Requesting a url
  console.log(req.url);
  url = req.url;

  res.statusCode = 200;
  res.setHeader('Content-Type''text/html');
  
  //Setting conditions for different pages url
  
  if (url=="/"){
    res.end(home);   //This means if url is / then display index.html 
  }
 
  else if (url=="/about.html"){
    res.end(about);    
  }
 
  else if (url=="/services.html"){
    res.end(services);    
  }
 
  else if (url=="/contact.html"){
    res.end(contact);    
  }
  
  else{res.statusCode = 404;
      console.log("page not found");}
});

//Running server
server.listen(porthostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});



index.html

<!DOCTYPE html>
<html lang="en">

<!-- Tough Web Learn by doing. -->
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home</title>
    <style>.....</style> /* bottom of blog*/
</head>
<body>
   
   <header>
    
    <nav class="navBar" >
        <ul> 
            <li> <a href="/">Home</a></li>
                <li> <a href="/about.html">About</a> </li>
                <li> <a href="/services.html">Services</a> </li>
                <li> <a href="/contact.html"> Contact us</a></li>
            </ul>

    </nav>
</header>
<h1>This is Home Page.</h1>
</body>
</html>


about.html

<!DOCTYPE html>
<html lang="en">

<!-- Tough Web Learn by doing. -->
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>About</title>
    <style>......</style> /* bottom of blog*/
</head>
<body>
   
   <header>
    
    <nav class="navBar" >
        <ul> 
            <li> <a href="/">Home</a></li>
                <li> <a href="/about.html">About</a> </li>
                <li> <a href="/services.html">Services</a> </li>
                <li> <a href="/contact.html"> Contact us</a></li>
            </ul>

    </nav>
</header>
<h1>This is About Page.</h1>
</body>
</html>



services.html

<!DOCTYPE html>
<html lang="en">

<!-- Tough Web Learn by doing. -->
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Services</title>
    <style>....</style> /* bottom of blog*/
</head>
<body>
   
   <header>
    
    <nav class="navBar" >
        <ul> 
            <li> <a href="/">Home</a></li>
                <li> <a href="/about.html">About</a> </li>
                <li> <a href="/services.html">Services</a> </li>
                <li> <a href="/contact.html"> Contact us</a></li>
            </ul>
    </nav>
</header>
<h1>This is Services Page.</h1>
</body>
</html>



contact.html

<!DOCTYPE html>
<html lang="en">

<!-- Tough Web Learn by doing. -->
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact</title>
    <style>....</style> /* bottom of blog*/
</head>
<body>
   
   <header>
    
    <nav class="navBar" >
        <ul> 
            <li> <a href="/">Home</a></li>
                <li> <a href="/about.html">About</a> </li>
                <li> <a href="/services.html">Services</a> </li>
                <li> <a href="/contact.html"> Contact us</a></li>
            </ul>

    </nav>
</header>
<h1>This is Contact Page.</h1>
</body>
</html>



<style>......</style>

   <style>

     h1{padding-left600px;
    colorgreen;}

    .navBar{
    background-colorrgb(165165223);
    padding1px 10px;
    border-radius15px; }
         
    .navBar ul{overflowauto;}
        
    .navBar li{floatleft;
    list-style-typenone;
    margin2px 10px; }

    .navBar li a{text-decorationnone;
    colorrgb(823235);
    font-weightbold;
    font-size23px;}
        
    .navBar li a:hover{background-coloryellow;
    colorrgb(104160);}

    </style>

 


Comments

Popular posts from this blog

INDEX OF ZEEK HTML,CSS and JS